#ifndef _AS_COMPONENT_H_
#define _AS_COMPONENT_H_

#include "ASObject.h"




NS_AS_BEGIN

//all comonent will use these macros
//declare compname and get function, use in class
#define ASComponentNameDeclare(component) private:\
											static class component* _ComName;\
											public:\
											static int getComNameStatic(){return (int)&_ComName;};\
											virtual int getComName(){return (int)&_ComName;};
//init the static param compname , use in cpp to prevent repeated include
#define ASComponentNameInstance(component) component* component::_ComName = nullptr;

class ASEntity;
class ASComponent:public ASObject
{
	ASComponentNameDeclare(ASComponent);
public:
	ASComponent();
	
	virtual ~ASComponent();
	virtual void destory() {setActive(false);};
	virtual void update(float dt){};
	virtual void updateBefore(){};
	virtual void updateAfter(){};
	virtual void onEnter(){};
	virtual void onExit(){};
	virtual void merge(ASComponent* newCom){};//merge data with same type componet
	void setHolder(ASEntity* holder);
	ASEntity* getHolder(){return _pHolder;};
	bool getActive(){return _bActive;};
	bool isMerge(){return _bMerge;};
	//const std::string getName(){return _name;}
	//void setName(const std::string& name){_name = name;}
	float getUpdateTick(){return _fUpdateTick;}
	void  setTimeCoefficient(float f){_fTimeCoefficient = f;}
	float getTimeCoefficient(){return _fTimeCoefficient;}
protected:
	void setActive(bool active){_bActive = active;};
	ASEntity* _pHolder;//holder
	float _fTimeCoefficient;
	float _fUpdateTick;
	bool _bActive;
	bool _bMerge;
private:
	friend ASEntity;
	void setUpdateMatchFlag(bool flag){_bUpdateMatch = flag;};
	bool getUpdateMatchFlag(){return _bUpdateMatch;}
	bool _bUpdateMatch;
};

NS_AS_END
#endif